/**
 * MiniGolf Scorecard
 * Copyright (C) 2010  MiriTheQuiet, http://minigolfscorecard.googlecode.com/
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package cz.mtq.mgsc.command;

import javax.microedition.lcdui.Displayable;

import cz.mtq.mgsc.MgscMidlet;

public abstract class AbstractCommand implements Command {

	private Displayable displayable;
	private javax.microedition.lcdui.Command command;
	private final MgscMidlet midlet;

	public AbstractCommand() {
		this.command = null;
		this.midlet = null;
	}

	public void setCommand(javax.microedition.lcdui.Command command) {
		this.command = command;
	}

	public AbstractCommand(javax.microedition.lcdui.Command command, MgscMidlet midlet) {
		super();
		this.command = command;
		this.midlet = midlet;
	}

	public Displayable getDisplayable() {
		return displayable;
	}

	public void setDisplayable(Displayable displayable) {
		this.displayable = displayable;
	}

	public javax.microedition.lcdui.Command getCommand() {
		return command;
	}

	public MgscMidlet getMidlet() {
		return midlet;
	}

	public void execute() throws Exception {
		exec();
		// dereference displayable
		this.displayable = null;
	}

	protected abstract void exec() throws Exception;

}
